package com.smritimap.demo.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by zxn on 2024/12/17.
 */
public class ArcAngleView extends View {
    private Paint mPaint;

    /**
     * 圆的宽度
     */
    private int mCircleWidth = 3;

    public ArcAngleView(Context context) {
        this(context, null);
    }

    public ArcAngleView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ArcAngleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mPaint = new Paint();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        mPaint.setAntiAlias(true);//取消锯齿
        //mPaint.setStyle(Paint.Style.FILL);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(mCircleWidth);
        mPaint.setColor(Color.CYAN);

        /**
         * 这是一个居中的圆
         */
        float x = (getWidth() - getHeight() / 2) / 2;
        float y = getHeight() / 4;

        RectF oval = new RectF(x, y, getWidth() - x, getHeight() - y);

        //canvas.drawArc(oval, 360, 140, true, mPaint);
        //canvas.drawArc(oval, -90, 120, false, mPaint);
        //canvas.drawArc(oval,90,110,false,mPaint);
        //canvas.drawArc(oval,0,90,false,mPaint);
        //canvas.drawArc(oval,0,45,false,mPaint);
        //drawArc(canvas, oval, 0, 135, false, mPaint);
        drawArc(canvas, oval, -90, 90, false, mPaint);
    }

    /**
     * 绘制圆弧
     *
     * @param oval       定义的圆弧的形状和大小的范围
     * @param startAngle 这个参数的作用是设置圆弧是从哪个角度来顺时针绘画的
     * @param sweepAngle 这个参数的作用是设置圆弧扫过的角度 ，我们从上面的代码就可以知道其中的作用了。
     * @param useCenter  这个参数的作用是设置我们的圆弧在绘画的时候，是否经过圆心、
     * @param paint      这个参数的作用是设置我们的画笔对象的属性
     */
    public void drawArc(Canvas canvas, RectF oval, float startAngle, float sweepAngle, boolean useCenter,
                        Paint paint) {
        canvas.drawArc(oval, startAngle, sweepAngle, useCenter, paint);
    }


}
